package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

import actions.Commands;

public class RequestMessages implements Runnable {

	private static final int SLEEP_TIME = 3000;
	int lastMsj;
	PrintWriter out;
	BufferedReader in;
	
	
	public RequestMessages( PrintWriter _out, BufferedReader _in ) 
	{
		super();
		this.lastMsj = 0;
		out=_out;
		in=_in;
	}

	@Override
	public void run() {
		while ( true )
		{
			out.println("#"+Commands.GET+" "+lastMsj );
	
			try {
				String requestedMsjs = in.readLine();
				String[] msjs = requestedMsjs.split(" ");
				lastMsj=Integer.parseInt(msjs[1]);
				
				for(int i=2;i<msjs.length;i++ )
				{
					System.out.println(msjs[i]);
				}
				
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			try {
				Thread.sleep(SLEEP_TIME);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

	}


}
